package top.xchch.tool.mockito.juejin;

import org.junit.Test;
import org.mockito.ArgumentCaptor;

import java.util.List;

import static org.junit.Assert.assertEquals;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.verify;

/**
 * 参数捕捉
 *
 * @author sai.zhang
 * @date 2021-08-31 15:14
 */
public class CapturingArgumentsTest14 {
    @Test
    public void testCapturingArguments() throws Exception {
        List mockedList = mock(List.class);
        ArgumentCaptor<String> argument = ArgumentCaptor.forClass(String.class);
        mockedList.add("John");
        //验证后再捕捉参数
        verify(mockedList).add(argument.capture());
        //验证参数
        assertEquals("John", argument.getValue());
    }

}
